//
//  AViewController.m
//  纪宇婚礼纪
//
//  Created by dllo on 15/12/21.
//  Copyright © 2015年 LT. All rights reserved.
//

#import "AViewController.h"
#import "ATableViewCell.h"
#import "BTableViewCell.h"
#import "CTableViewCell.h"
#import "AFN.h"
#import "LunMoTu.h"

@interface AViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain) UITableView *mytable;
@property (nonatomic, retain) LunMoTu *lunmo;
@end

@implementation AViewController
-(void)dealloc{
    [_allarrayLunMoTu release];
    [_mytable release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
  
    self.view.backgroundColor = [UIColor grayColor];
    self.mytable = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.mytable.delegate = self;
    self.mytable.dataSource = self;
    [self.view addSubview:self.mytable];
    [_mytable release];
    
    self.allarrayLunMoTu = [NSMutableArray array];
    
    //注册
    [self.mytable registerClass:[ATableViewCell class] forCellReuseIdentifier:@"cella"];
    [self.mytable registerClass:[BTableViewCell class] forCellReuseIdentifier:@"cellb"];
    [self.mytable registerClass:[CTableViewCell class] forCellReuseIdentifier:@"cellc"];
    
    NSString *str = @"http://c.3g.163.com/nc/article/headline/T1348647853363/0-20.html?from=toutiao&passport=&devId=NAWF9kofeo6iqNVtcfL9m4eYLEDWfP2E749tss0ESKrlrPqGP1BDilGrKPrCqIau&size=20&version=5.4.2&spever=false&net=wifi&lat=YFX3buxHshwhnCB1j31%2BoA%3D%3D&lon=7oNoVO4jxtIecvcLdNv8wQ%3D%3D&ts=1448247113&sign=8kYgHSu4hBwMrPaWJxcymmBpbEGihpckMWSWq0FaZGZ48ErR02zJ6%2FKXOnxX046I&encryption=1";
    [AFN getWithNsstring:str block:^(id result) {
        NSMutableArray *array = [result objectForKey:@"T1348647853363"];
        for (NSMutableDictionary *dic in array) {
            NSMutableArray *arr = [dic objectForKey:@"ads"];
            for (NSMutableDictionary *Dic in arr) {
        
                LunMoTu *lun = [[LunMoTu alloc]init];
                [lun setValuesForKeysWithDictionary:Dic];

                [self.allarrayLunMoTu addObject:lun];
                }
        }
        

        [self.mytable reloadData];
        
    } error:^(NSError *error) {
        
        
    }];
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.allarrayLunMoTu.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  
    
    if (indexPath.row == 0) {
        BTableViewCell *cellb = [tableView dequeueReusableCellWithIdentifier:@"cellb"];
       cellb.lunmo = [self.allarrayLunMoTu objectAtIndex:indexPath.row];
//        cellb.lunmo = [self.allarrayLunMoTu objectAtIndex:1];
//        cellb.lunmo = [self.allarrayLunMoTu objectAtIndex:2];
//        cellb.lunmo = [self.allarrayLunMoTu objectAtIndex:3];
//        cellb.lunmo = [self.allarrayLunMoTu objectAtIndex:4];

        
    
          return cellb;
    }
    if (indexPath.row == 3) {
        CTableViewCell *cellc = [tableView dequeueReusableCellWithIdentifier:@"cellc"];
        return cellc;
    }
    ATableViewCell *cella = [tableView dequeueReusableCellWithIdentifier:@"cella"];
    
    return cella;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 188;
    }
    if (indexPath.row == 3) {
        return 137;
    }
    return 94;
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
